// MeterAnalyseMapper.java
package com.ruoyi.water.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.water.domain.MeterAnalyse;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 水表分析数据Mapper接口
 */
public interface MeterAnalyseMapper extends BaseMapper<MeterAnalyse> {

    /**
     * 批量插入水表分析数据，忽略重复记录（基于meterId+analyseDate联合约束）
     * @param list 待插入的MeterAnalyse列表
     * @return 实际插入成功的记录数
     */
    @Insert("<script>" +
            "INSERT IGNORE INTO t_meteranalyse (" +
            "  meterId, " +
            "  meterName, " +
            "  todayMinVal, " +
            "  todayMinvalTime, " +
            "  todayMinvalPercent, " +
            "  todayMinvalBias, " +
            "  monthagoMinval, " +
            "  monthagoMinvalPercent, " +
            "  monthagoMinvalBias, " +
            "  yearagoMinval, " +
            "  yearagoMinvalPercent, " +
            "  yearagoMinvalBias, " +
            "  todayUsage, " +
            "  todayUsagePercent, " +
            "  todayUsageBias, " +
            "  monthagoUsagePercent, " +
            "  monthagoUsageBias, " +
            "  monthagoUsage, " +
            "  yearagoUsagePercent, " +
            "  yearagoUsageBias, " +
            "  yearagoUsage, " +
            "  analyseDate, " +
            "  recordTime " +
            ") VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "( " +
            "  #{item.meterId}, " +
            "  #{item.meterName}, " +
            "  #{item.todayMinVal}, " +
            "  #{item.todayMinvalTime}, " +
            "  #{item.todayMinvalPercent}, " +
            "  #{item.todayMinvalBias}, " +
            "  #{item.monthagoMinval}, " +
            "  #{item.monthagoMinvalPercent}, " +
            "  #{item.monthagoMinvalBias}, " +
            "  #{item.yearagoMinval}, " +
            "  #{item.yearagoMinvalPercent}, " +
            "  #{item.yearagoMinvalBias}, " +
            "  #{item.todayUsage}, " +
            "  #{item.todayUsagePercent}, " +
            "  #{item.todayUsageBias}, " +
            "  #{item.monthagoUsagePercent}, " +
            "  #{item.monthagoUsageBias}, " +
            "  #{item.monthagoUsage}, " +
            "  #{item.yearagoUsagePercent}, " +
            "  #{item.yearagoUsageBias}, " +
            "  #{item.yearagoUsage}, " +
            "  #{item.analyseDate}, " +
            "  #{item.recordTime} " +
            ")" +
            "</foreach>" +
            "</script>")
    int insertBatchIgnoreDuplicates(@Param("list") List<MeterAnalyse> list);
}